home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1995 October
/
EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso
/
Aminet
/
util
/
dtype
/
FontDT_1_0.lha
/
Src
/
prefs.c
< prev
Wrap
C/C++ Source or Header
|
1995-04-22
|
2KB
|
82 lines
/*
** prefs.c - prefrences handling for Font DataType class
** Copyright © 1995 Michael Letowski
*/
#include <exec/types.h>
#include <exec/memory.h>
#include <dos/dos.h>
#include <dos/rdargs.h>
#include <support/types.h>
#include "classbase.h"
#include "prefs.h"
#include <proto/exec.h>
#include <proto/dos.h>
#define BUF_LEN 256
#define PREFS_PATH1 "PROGDIR:Prefs/DataTypes/font.prefs"
#define PREFS_PATH2 "ENV:DataTypes/font.prefs"
STATIC LBOOL ReadPrefs(struct ClassBase *cb, struct PrefsHandle *ph,
struct Opts *opts, STRPTR name);
struct PrefsHandle *GetFontPrefs(struct ClassBase *cb, struct Opts *opts)
{
struct PrefsHandle *PH;
try(newv(PH,MEMF_CLEAR), NO_PREFS);
try(PH->ph_RDA=AllocDosObject(DOS_RDARGS,NULL), NO_RDA);
fset(PH->ph_RDA->RDA_Flags,RDAF_NOPROMPT); /* Disable prompts */
clear(opts); /* Set defaults */
unless(ReadPrefs(cb,PH,opts,PREFS_PATH1))
ReadPrefs(cb,PH,opts,PREFS_PATH2);
return(PH);
except(NO_RDA, FreeDosObject(DOS_RDARGS,PH->ph_RDA));
except(NO_PREFS, deletev(PH));
return(NULL);
} /* GetFontPrefs */
VOID FreeFontPrefs(struct ClassBase *cb, struct PrefsHandle *ph)
{
ph->ph_RDA->RDA_Buffer=NULL; /* Don't free buffer */
FreeArgs(ph->ph_Args);
FreeDosObject(DOS_RDARGS,ph->ph_RDA);
deletev(ph);
} /* FreeFontPrefs */
STATIC LBOOL ReadPrefs(struct ClassBase *cb, struct PrefsHandle *ph,
struct Opts *opts, STRPTR name)
{
struct RDArgs *RDA=ph->ph_RDA;
CHAR Buffer[BUF_LEN];
ULONG Len;
BPTR FH;
LBOOL Result=FALSE;
try(FH=Open(name,MODE_OLDFILE), NO_FILE);
RDA->RDA_Source.CS_Buffer=Buffer; /* Set up buffer to read from */
/* Read args */
while(FGets(FH,Buffer,BUF_LEN-1)) /* Last byte spare */
{
if(ph->ph_Args)
FreeArgs(ph->ph_Args); /* Free previous line args */
clear(opts); /* Clear args */
Len=strlen(Buffer); /* Calculate length */
Buffer[Len]='\n'; /* New line char */
Buffer[Len+1]='\0'; /* String terminator */
RDA->RDA_Source.CS_Length=Len+1; /* Set up string len */
RDA->RDA_Source.CS_CurChr=0; /* Set up current char */
RDA->RDA_Buffer=NULL; /* As documented in AutoDocs */
ph->ph_Args=ReadArgs(TEMPLATE,(LONG *)opts,RDA); /* Read from file */
}
Result=(ph->ph_Args) ? TRUE : FALSE;
except(NO_FILE, Close(FH));
return(Result);
} /* ReadPrefs */